package com.hbvtc.xxxy.nikeSale.frames;

import java.awt.Color;
import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.hbvtc.xxxy.nikeSale.daos.Vipdao;

public class UpdateVipNike extends JFrame implements ActionListener {
	JLabel jLabel1, jLabel2, jLabel3, jLabel4, jLabel5;
	JTextField jTextField1, jTextField2, jTextField3, jTextField4, jTextField5;
	JPanel jPanel;
	JButton jButton1, jButton2;
	Vipdao vipdao = new Vipdao();

	public UpdateVipNike() {
		this.setTitle("会员更新界面");
		this.setSize(1000, 700);
		this.setLocationRelativeTo(null);
		this.setVisible(true);

		// 设置标题栏的图标
		ImageIcon imageIcon = new ImageIcon(getClass().getResource("01.png"));
		this.setIconImage(imageIcon.getImage());
		// 背景图片的路径
		String path = "images/001.jpg";
		ImageIcon background = new ImageIcon(path);
		// 把背景图片显示在一个标签里面
		JLabel label = new JLabel(background);
		// 把标签的大小位置设置为图片刚好填充整个面板
		label.setBounds(0, 0, this.getWidth(), this.getHeight());
		// 把内容窗格转化为JPanel，否则不能用方法setOpaque()来使内容窗格透明
		JPanel imagePanel = (JPanel) this.getContentPane();
		imagePanel.setOpaque(false);
		// 把背景图片添加到分层窗格的最底层作为背景
		this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));

		this.setLayout(null);
		jTextField1 = new JTextField();
		jTextField2 = new JTextField();
		jTextField3 = new JTextField();
		jTextField4 = new JTextField();
		jTextField5 = new JTextField();
		jLabel1 = new JLabel("请输入要更新的会员:");
		jLabel2 = new JLabel("会员密码:");
		jButton1 = new JButton("更新密码");
		jLabel3 = new JLabel("请输入新的密码:");
		jLabel3.setForeground(Color.red);
		jLabel4 = new JLabel("请重复输入以确认:");
		jLabel4.setForeground(Color.red);
		jButton2 = new JButton("会员充值");
		jLabel5 = new JLabel("请输入充值的金额:");

		this.add(jButton1);
		this.add(jButton2);
		this.add(jTextField1);
		this.add(jTextField2);
		this.add(jTextField3);
		this.add(jTextField4);
		this.add(jTextField5);
		this.add(jLabel1);
		this.add(jLabel2);
		this.add(jLabel3);
		this.add(jLabel4);
		this.add(jLabel5);

		jLabel1.setBounds(150, 100, 240, 30);
		jLabel1.setFont(new Font(null, 0, 24));
		jLabel2.setBounds(150, 200, 240, 30);
		jLabel2.setFont(new Font(null, 0, 24));
		jLabel3.setBounds(150, 300, 240, 30);
		jLabel3.setFont(new Font(null, 0, 24));
		jLabel4.setBounds(150, 400, 240, 30);
		jLabel4.setFont(new Font(null, 0, 24));
		jLabel5.setBounds(150, 500, 240, 30);
		jLabel5.setFont(new Font(null, 0, 24));
		jButton1.setBounds(670, 400, 150, 30);
		jButton1.setFont(new Font(null, 0, 24));
		jButton2.setBounds(670, 500, 150, 30);
		jButton2.setFont(new Font(null, 0, 24));

		jTextField1.setBounds(400, 100, 200, 30);
		jTextField1.setFont(new Font(null, 0, 24));
		jTextField2.setBounds(400, 200, 200, 30);
		jTextField2.setFont(new Font(null, 0, 24));
		jTextField3.setBounds(400, 300, 200, 30);
		jTextField3.setFont(new Font(null, 0, 24));
		jTextField4.setBounds(400, 400, 200, 30);
		jTextField4.setFont(new Font(null, 0, 24));
		jTextField5.setBounds(400, 500, 200, 30);
		jTextField5.setFont(new Font(null, 0, 24));

		jButton1.addActionListener(this);
		jButton2.addActionListener(this);
	}

	public static void main(String[] args) {
		new UpdateVipNike().setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		if (e.getSource() == jButton1) {
			try {
				if (vipdao.ss(jTextField1.getText(), jTextField2.getText()) == true) {
					if (jTextField3.getText().equals(jTextField4.getText())) {
						vipdao.update(jTextField3.getText(),
								jTextField1.getText());
						JOptionPane.showMessageDialog(UpdateVipNike.this,
								"修改成功");
					} else {
						JOptionPane.showMessageDialog(UpdateVipNike.this,
								"修改会员失败");
					}
				} else {
					JOptionPane.showMessageDialog(UpdateVipNike.this, "会员不存在");
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
		if (e.getSource() == jButton2) {
			try {
				if (vipdao.ss(jTextField1.getText(), jTextField2.getText()) == true) {
					vipdao.updateprice(jTextField5.getText(),
							jTextField1.getText());
					JOptionPane.showMessageDialog(UpdateVipNike.this, "充值成功");
				} else {
					JOptionPane.showMessageDialog(UpdateVipNike.this, "会员不存在");
				}
			} catch (HeadlessException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}

	}

}
